from appengine_django.models import BaseModel
from google.appengine.ext import db
from google.appengine.api import users


from helpers.misc import new_skey

#Only few informations for now.
#openid/google account provide user information (nickname/username/email)
class Profile(BaseModel):
        s_key =  db.StringProperty(multiline=False, required=False, indexed=True)
        author = db.UserProperty(required=False)

	fname = db.StringProperty(multiline=False)
	lname = db.StringProperty(multiline=False)
        def save(self):
                if not self.author: self.author = users.get_current_user()
                if not self.s_key: self.s_key = new_skey(self)
                return super(Profile, self).save()

class Invite(BaseModel):
        s_key =  db.StringProperty(multiline=False, required=False, indexed=True)
        author = db.UserProperty(required=False)

        user = db.UserProperty(required=True)
        entry = db.ReferenceProperty(required=True)
	#permission mask: 0=None, 1=Comment/Read, 2=Edit/Comment, >0 -Read
        permission = db.IntegerProperty(required=True)

	def is_owner(self):
		if users.get_current_user() == self.author: return True
		return False	

	def get_absolute_url(self): return "invite/%s" % self.s_key

        def save(self):
                if not self.author: self.author = users.get_current_user()
                if not self.s_key: self.s_key = new_skey(self)
                return super(Invite, self).save()
